﻿using UnityEngine;
using System.Collections;

public class FinishMenu : MonoBehaviour {

	public GameObject gameOverText;
	public GameObject score;
	public GameObject exitButton;
	public GameObject restartButton;
	public GameObject screenFade;
	public TextMesh distanceText;
	public TextMesh bestText;

	private Color fadeCol = new Color(0, 0, 0, 0.5f);
	/// <summary>
	/// Activate this instance.
	/// </summary>
	public void Activate()
	{
		distanceText.text = GameManager.Game.LastScore.ToString() + "m";
		bestText.text = GameManager.Game.BestScore.ToString() + "m";

		MenueAni.FadeTo (screenFade, fadeCol, 0.3f, 0);
		MenueAni.MoveTo(gameOverText, new Vector3(0, 0.5f, 0), 0.4f, 0.0f);
		MenueAni.MoveTo(score, new Vector3(-1.0f, 0.1f, 0), 0.4f, 0.1f);
		MenueAni.MoveTo(exitButton, new Vector3(-1.35f, -1.8f, 0), 0.4f, 0.3f);
		MenueAni.MoveTo(restartButton, new Vector3(1.35f, -1.8f, 0), 0.4f, 0.3f);

		SoundManager.PauseMusic(0.5f);
	}
	/// <summary>
	/// Raises the restart event.
	/// </summary>
	public void OnRestart()
	{
		MenueAni.MoveTo(gameOverText, new Vector3(0, 5, 0), 0.4f, 0.1f);
		MenueAni.MoveTo(score, new Vector3(0, -4, 0), 0.4f, 0.1f);
		MenueAni.MoveTo(exitButton, new Vector3(-10, -1.5f, 0), 0.4f, 0.0f);
		MenueAni.MoveTo(restartButton, new Vector3(10, -1.5f, 0), 0.4f, 0.0f);

		MenueAni.FadeTo (screenFade, Color.black, 0.3f, 0.1f);
		GameManager.Game.Invoke ("Restart", 0.7f);
		MenueAni.FadeTo (screenFade, Color.clear, 0.3f, 0.7f);
	}
	/// <summary>
	/// Raises the back to menu event.
	/// </summary>
	public void OnBackToMenu()
	{
		MenueAni.MoveTo(gameOverText, new Vector3(0, 5, 0), 0.4f, 0.1f);
		MenueAni.MoveTo(score, new Vector3(0, -4, 0), 0.4f, 0.1f);
		MenueAni.MoveTo(exitButton, new Vector3(-10, -1.5f, 0), 0.4f, 0.0f);
		MenueAni.MoveTo(restartButton, new Vector3(10, -1.5f, 0), 0.4f, 0.0f);
		// fade to black (the title screen handles fading back in)
		MenueAni.FadeTo(screenFade, Color.black, 0.3f, 0.1f);

		GameManager.Game.Invoke("ShowTitleScreen", 0.7f);
	}
}
